package twel.probenprophet.profile.spells.xdiml2;

import java.io.Reader;
import java.util.Collection;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import twel.probenprophet.base.exceptions.ProbenprophetException;
import twel.probenprophet.profile.spells.xdiml2.jaxb.SpellDefinition;
import twel.probenprophet.profile.spells.xdiml2.jaxb.XdimlRootElement;

public class SpellXmlLoader {

	public Collection<SpellDefinition> load(Reader reader) {
		try {
			JAXBContext context = JAXBContext.newInstance(XdimlRootElement.class);
			Unmarshaller unmarshaller = context.createUnmarshaller();
			XdimlRootElement rootElement = (XdimlRootElement) unmarshaller.unmarshal(reader);
			return rootElement.getXdimlContents().getSpells();
		} catch (JAXBException e) {
			throw new ProbenprophetException("JAXB unmarshalling failed", e);
		}
	}

}
